﻿using System.Windows;
using System.Windows.Controls;
using Controllers;
using Views.Moduler;

namespace Views
{
    public partial class MainWindow
    {
        #region Properties

        public Søgning TabSøgning { get; private set; }
        public Software TabSoftware { get; private set; }
        public Hardware TabHardware { get; private set; }
        public Brugere TabBrugere { get; private set; }
        public Afdelinger TabAfdelinger { get; private set; } 

        #endregion

        #region Creation

        public MainWindow()
        {
            InitializeComponent();

            // gør codebehind filen tilgængelig i XAML filen
            DataContext = this;

            var controller = new Controller();

            TabSøgning = new Søgning(controller);
            TabSoftware = new Software(controller);
            TabHardware = new Hardware(controller);
            TabBrugere = new Brugere(controller);
            TabAfdelinger = new Afdelinger(controller);
        } 

        #endregion

        #region Eventhandlers

        private void Close(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void AboutInformation_Click(object sender, RoutedEventArgs e)
        {
            var information = new Information();
            information.ShowDialog();
        }

        UserControl _currentTab;
        private void MainTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var uc = ((TabItem)MainTabControl.SelectedItem).Content as UserControl;

            if (uc != _currentTab)
            {
                _currentTab = uc;

                var søgning = uc as Søgning;
                if (søgning != null)
                {
                    søgning.OpdaterSide();
                }

                var brugere = uc as Brugere;
                if (brugere != null)
                {
                    brugere.OpdaterSide();
                }

                var afdelinger = uc as Afdelinger;
                if (afdelinger != null)
                {
                    afdelinger.OpdaterSide();
                }

                var hardware = uc as Hardware;
                if (hardware != null)
                {
                    hardware.OpdaterSide();
                }

                var software = uc as Software;
                if (software != null)
                {
                    software.OpdaterSide();
                }
            }
        } 

        #endregion
    }
}
